function getYearAjax(){

    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option = {
        type:"post",
        data:"uid=" + myuid + "&year=" + $("#yearSelct").val(),
        dataType:"json",
        success:function(msg) {
            showYearReport(msg.zhiTypeNameAndmoneyDto);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }

    };
    $.ajax(ip + "report/sumyeartypezhidata",option);
}
function showYearReport(param) {

    var arr = param;
    var nameArr = [];
    var moneyArr = [];
    for (var i = 0 ; i < arr.length ; i++){
        nameArr.push(arr[i].name);
        if (arr[i].money==null){
            moneyArr.push(0);
        }else{
            moneyArr.push(arr[i].money);
        }
    }
    var year_option = {
        title : {
            text: '分类支出报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '35%',
            containLabel: true
        },
        legend: {
            data: nameArr
        },
        xAxis : [
            {
                type : 'category',
                data : nameArr,
                splitLine:{
                    show:true
                },
                axisLabel: {
                    interval:0,
                    rotate:40
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'金额',
                type:'bar',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                barMaxWidth: '20',
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:moneyArr,
            }
        ]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(year_option);
}

function getMonthAjax(){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option = {
        type:"post",
        data:"uid=" + myuid + "&year=" + $("#yearSelct").val() + "&month=" + $("#monSelct").val(),
        dataType:"json",
        success:function(msg) {
            showMonthReport(msg.zhiTypeNameAndmoneyDto);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }

    };
    $.ajax(ip + "report/summonthtypezhidata",option);
}
function showMonthReport(param) {

    var arr = param;
    var nameArr = [];
    var moneyArr = [];
    for (var i = 0 ; i < arr.length ; i++){
        nameArr.push(arr[i].name);
        if (arr[i].money==null){
            moneyArr.push(0);
        }else{
            moneyArr.push(arr[i].money);
        }
    }
    var year_option = {
        title : {
            text: '分类支出报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '35%',
            containLabel: true
        },
        legend: {

            data: nameArr
        },
        xAxis : [
            {
                type : 'category',
                data : nameArr,
                splitLine:{
                    show:true
                },
                axisLabel: {
                    interval:0,
                    rotate:40
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'金额',
                type:'bar',
                barMaxWidth: '20',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:moneyArr,
            }
        ]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(year_option);
}

function getJiduAjax(){
    var myuid = uid;
    var ip = ip_port;
    if(myuid==null||myuid==""){
        window.parent.location.href=ip + "front/tologin";
    }
    var option = {
        type:"post",
        data:"uid=" + myuid + "&year=" + $("#yearSelct").val() + "&quarter=" + $("#jiduSelct").val(),
        dataType:"json",
        success:function(msg) {
            showJiduReport(msg.zhiTypeNameAndmoneyDto);
        },
        beforeSend:function (xhr) {
            if(myuid==null||myuid==""){
                return false;
            }
        },
        error:function (error) {
            alert("error");
        }

    };
    $.ajax(ip + "report/sumjidutypezhidata",option);
}
function showJiduReport(param) {

    var arr = param;
    var nameArr = [];
    var moneyArr = [];
    for (var i = 0 ; i < arr.length ; i++){
        nameArr.push(arr[i].name);
        if (arr[i].money==null){
            moneyArr.push(0);
        }else{
            moneyArr.push(arr[i].money);
        }
    }
    var year_option = {
        title : {
            text: '分类支出报表',
            subtext: '元'
        },
        tooltip : {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '35%',
            containLabel: true
        },
        legend: {

            data: nameArr
        },
        xAxis : [
            {
                type : 'category',
                data : nameArr,
                splitLine:{
                    show:true
                },
                axisLabel: {
                    interval:0,
                    rotate:40
                },
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value',
                splitLine:{
                    show:false
                },
                splitArea:{
                    show:true,
                },
            }
        ],
        series : [
            {
                name:'金额',
                type:'bar',
                barMaxWidth: '20',
                label:{
                    normal:{
                        show:true,
                        position:'top'
                    }
                },
                itemStyle:{
                    normal:{
                        color:function(d){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
                    }
                },
                data:moneyArr,
            }
        ]
    };

    var myChart = echarts.init(document.getElementById('shouzhi_rep'));
    myChart.setOption(year_option);
}

$(function () {


    var flag = "year";


    $("#monSelct").hide();
    $("#jiduSelct").hide();
	$("#monBtn").addClass("vist");
    $("#jiduBtn").addClass("vist");
	 $("#yearBtn").addClass("vist");
	
    $("#yearBtn").addClass("active");
    getYearAjax();
    $("#yearBtn").click(function () {
        $("#yearBtn").addClass("vist");
        $("#yearBtn").addClass("active");
        $("#monBtn").removeClass("active");
        $("#jiduBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").hide();
        $("#jiduSelct").hide();
        getYearAjax();

        $("#yearSelct").unbind().change(function () {

            getYearAjax();
        });
    });

    $('#yearBtn').trigger("click");

    $("#monBtn").click(function () {

        $("#monBtn").addClass("active");
        $("#yearBtn").removeClass("active");
        $("#jiduBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").show();
        $("#jiduSelct").hide();

        getMonthAjax();
        $("#monSelct").unbind().change(function () {
            getMonthAjax();

        })
        $("#yearSelct").unbind().change(function () {

            getMonthAjax();

        });
    });
    $("#jiduBtn").click(function () {

        $("#jiduBtn").addClass("active");
        $("#yearBtn").removeClass("active");
        $("#monBtn").removeClass("active");
        $("#yearSelct").show();
        $("#monSelct").hide();
        $("#jiduSelct").show();
        getJiduAjax();

        $("#yearSelct").unbind().change(function () {

            getJiduAjax();
        });
        $("#jiduSelct").unbind().change(function () {

            getJiduAjax();
        });
    });



})